home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / lib / emacs / site-lisp / su.el.z / su.el
Encoding:
Text File  |  1994-08-02  |  1.9 KB  |  46 lines

  1. ;; Mark the buffer modifiable with ^X^Q (as others pointed out).  Edit
  2. ;; it.  Save it somewhere you can write with ^X^W (like ~/ or /tmp/).
  3. ;; Then use su-command (appended below) to move or copy the file over the
  4. ;; old version, perhaps moving the previous one out of the way first if
  5. ;; necessary.  Elisp after my .sig.
  6. ;; 
  7. ;; (anticipating the nits: yes, I know the password echos as you type it.
  8. ;; However, putting the two arguments in the order they are at least
  9. ;; overwrites the minibuffer as soon as you finish the password.  Anyone
  10. ;; who wants to add the get-a-string-sliently logic to the following is
  11. ;; welcome to do it and repost).
  12. ;; --
  13. ;; /jr, nee John Robinson     Life did not take over the globe by combat,
  14. ;; jr@bbn.com or bbn!jr          but by networking -- Lynn Margulis
  15.  
  16. (defun su-command (password command)
  17.   "Prompt for root password and a command, then do the latter as root."
  18.   (interactive "sRoot password: \nsCommand: ")
  19.   (let ((buffer (get-buffer-create "*Shell Command Output*"))
  20.         proc)
  21.     (save-excursion
  22.           (set-buffer buffer)
  23.           (erase-buffer))
  24.     (setq proc (start-process "su-emacs" buffer "/bin/su"
  25.                               "-c" command))
  26.     (if (save-excursion
  27.           (set-buffer buffer)
  28.           (goto-char (point-min))
  29.           (while (not (looking-at "Password:"))
  30.             (accept-process-output proc)
  31.             (goto-char (point-min)))
  32.           (erase-buffer)
  33.           (send-string proc (concat password "\n"))
  34.           (while (not (looking-at "\n"))
  35.             (accept-process-output proc)
  36.             (goto-char (point-min)))
  37.           (delete-char 1)
  38.           (while (not (equal (process-status proc) 'exit))
  39.             (accept-process-output))
  40.           (> (buffer-size) 0))
  41.         (set-window-start (display-buffer buffer) 1)
  42.       (message "(Command completed with no output)"))))
  43.  
  44. ;;; suggested binding (# is the prompt when superuser):
  45. ;;; (global-set-key "\e#" 'su-command)
  46.